package main

import (
	"image"
	"image/color"

	"code.google.com/p/jnj/graphics"
	"code.google.com/p/jnj/graphics/text"
)

const tagsize = 12

type window struct {
	tag   *text.Buffer
	edit  *text.Buffer
	dirty bool
}

func newWindow(r image.Rectangle) *window {
	w := new(window)

	tagr := r
	tagr.Max.Y = r.Min.Y + tagsize
	editr := r
	editr.Min.Y = tagr.Max.Y + 1

	opts := text.Options{
		Rect:         editr,
		BGCol:        color.RGBA{R: 0xFF, G: 0xFF, B: 0xEA, A: 0xFF},
		FontPath:     fontpath,
		KeyboardChan: make(chan rune),
		MouseChan:    make(chan *graphics.MouseEvent),
		ClipChan:     clipchan,
	}
	var err error
	w.edit, err = text.NewBuffer(opts)
	die(err)

	opts = text.Options{
		Rect:         tagr,
		BGCol:        color.RGBA{R: 0xEA, G: 0xFF, B: 0xFF, A: 0xFF},
		FontPath:     fontpath,
		KeyboardChan: make(chan rune),
		MouseChan:    make(chan *graphics.MouseEvent),
		ClipChan:     clipchan,
	}
	w.tag, err = text.NewBuffer(opts)
	die(err)

	return w
}

func (w *window) resize(r image.Rectangle) {
	drawborder(mainwin.tag)

	tagr := r
	tagr.Max.Y = screenbuf.R.Min.Y + 12
	w.tag.Resize(tagr)

	//outr := r
	//outr.Min.Y = outr.Max.Y - outbufheight
	//outbuf.Resize(outr)

	editr := r
	editr.Min.Y = tagr.Max.Y + 1
	//editr.Max.Y = outr.Min.Y - 1
	w.edit.Resize(editr)
}
